package planit.model;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.io.Serializable;


public class Event implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static int lastIdUsed;
	private Date startTime; 
	private int duration;
	private ArrayList<Person> persons;
	private String name;
	private String description;
	private String place;
	private EventType eventType;
	private int Id;

	public int getId(){
		return Id;
	}

	public Event() {
		Id = ++lastIdUsed;
		persons = new ArrayList<Person>();
	}

	public Event(int Id, String name, EventType eventType, Date startTime, int duration, 
			String description, String place, ArrayList<Person> persons) {
		this.Id = Id;
		Event.lastIdUsed = Id;
		setName(name);
		setEventType(eventType);
		setStartTime(startTime);
		setDuration(duration);
		setDescription(description);
		setPlace(place);
		this.persons = persons;
	}

	public Event(EventType eventType, Date startTime){
		this();
		this.eventType = eventType;
		this.startTime = startTime;
		this.duration = 60;
	}

	public Event(EventType eventType, Date startTime, int duration){
		this();
		this.eventType = eventType;
		this.startTime = startTime;
		this.duration = duration;
	}

	public void addPerson(Person person){
		persons.add(person);
	}

	public void removePerson(Person person){
		persons.remove(person);
	}

	public void addPersons(ArrayList<Person> persons){
		this.persons.addAll(persons);
	}

	public void setName(String name){
		this.name = name;
	}

	public void setDescription(String description){
		this.description = description;
	}

	public void setStartTime(Date startTime){
		this.startTime = startTime;
	}

	public void setDuration(int duration){
		this.duration = duration;
	}

	public void setPlace(String place){
		this.place = place;
	}

	public void setEventType(EventType eventType){
		this.eventType = eventType;
	}

	public ArrayList<Person> getPersons(){
		return persons;
	}

	public String getName(){
		return name;
	}

	public String getDescription(){
		return description;
	}

	public Date getStartTime(){
		return startTime;
	}

	public int getDuration(){
		return duration;
	}

	public String getPlace(){
		return place;
	}

	public EventType getEventType(){
		return eventType;
	}

	public Date getEndTime() {
		Calendar cal = new GregorianCalendar();
		cal.setTime(startTime);
		cal.add(Calendar.MINUTE, duration);
		return cal.getTime();
	}
}
